﻿using System.IO;

namespace QuickRunCore.Helper
{
    public class FileHelper
    {
        /// <summary>
        /// 获取执行文件所在目录
        /// </summary>
        /// <returns></returns>
        public static string GetProcDir()
        {
            return System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName.Replace(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName,"");
        }


        /// <summary>
        /// 保持文件信息
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="fileValue">文件内容</param>
        public static void SaveFileInfo(string filePath, string fileValue)
        {
            using (StreamWriter _sw = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
            {
                _sw.Write(fileValue);
            }
        }


        /// <summary>
        /// 读取文件信息
        /// </summary>
        public static string ReadFileInfo(string filePath)
        {
            if (File.Exists(filePath))
            {
                using (StreamReader _sr = new StreamReader(filePath, System.Text.Encoding.UTF8))
                {
                    string _s = _sr.ReadLine();
                    return _s;
                }
            }
            return "";
        }

    }
}
